#!/usr/bin/env bash

# This script uses MESOS_SOURCE_DIR and MESOS_BUILD_DIR which come
# from configuration substitutions.
MESOS_SOURCE_DIR=@abs_top_srcdir@
MESOS_BUILD_DIR=@abs_top_builddir@

# Locate Java from environment or use configure discovered location.
JAVA_HOME=${JAVA_HOME-@JAVA_HOME@}
JAVA=${JAVA-${JAVA_HOME}/bin/java}

# Use colors for errors.
. ${MESOS_SOURCE_DIR}/support/colors.sh

PROTOBUF_JAR=@PROTOBUF_JAR@

test ! -e ${PROTOBUF_JAR} && \
  echo "${RED}Failed to find ${PROTOBUF_JAR}${NORMAL}" && \
  exit 1

MESOS_JAR=${MESOS_BUILD_DIR}/src/java/target/mesos-@PACKAGE_VERSION@.jar

test ! -e ${MESOS_JAR} && \
  echo "${RED}Failed to find ${MESOS_JAR}${NORMAL}" && \
  exit 1

EXAMPLES_JAR=${MESOS_BUILD_DIR}/src/examples.jar

test ! -e ${EXAMPLES_JAR} && \
  echo "${RED}Failed to find ${EXAMPLES_JAR}${NORMAL}" && \
  exit 1

# Need to run in the directory containing this script so that the
# framework is able to find the executor.
cd `dirname ${0}`

exec ${JAVA} -cp ${PROTOBUF_JAR}:${MESOS_JAR}:${EXAMPLES_JAR} \
  -Djava.library.path=${MESOS_BUILD_DIR}/src/.libs \
  TestMultipleExecutorsFramework "${@}"
